package com.ea.eadp.nexus.test.pageDefinition.newconsole;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;


public class UnderageOriginAccountPage extends ConsoleBasePage {
    public static final String originIdInputBox = "originId";
    public static final String passwordInputBox = "loginPassword";
    public static final String createButton = "createBtn";

    public UnderageOriginAccountPage(WebDriver driver) {
        super(driver, UnderageOriginAccountPage.class, createButton);
    }

    public void create() {
        sendControllerKey(Keys.RIGHT);
        sendControllerKey('A');
    }

    public void enterOriginId(String originId) {
        sendControllerKey('A');
        log.info("Enter Origin Id:" + originId);
        sendInput(originIdInputBox, originId);
        clickBlank("//div[@id='panel-underage-login']//div[@class='titleBar']");
    }

    public void enterPassword(String password) {
        log.info("Enter Password:" + password);
        sendInput(passwordInputBox, password);
        clickBlank("//div[@id='panel-underage-login']//div[@class='titleBar']");
        sendControllerKey('A');
    }

    public String getTitle() {
        return getElementStringByXPath("//div[@id='panel-underage-welcome']//span[@class='title']");
    }

    public String getDescription() {
        return getElementStringByXPath("//div[@id='panel-underage-welcome']//p[@class='description']");
    }

    public String getLoginTitle() {
        return getElementStringByXPath("//div[@id='panel-underage-login']//span[@class='title']");
    }

    public String getLoginDescription() {
        return getElementStringByXPath("//div[@id='panel-underage-login']//p[@class='description']");
    }

    public String getOriginIdLabel() {
        return getElementStringByXPath("//li[@id='origin-id-container']//label[@class='origin-ux-textbox-label']");
    }

    public String getPasswordLabel() {
        return getElementStringByXPath("//li[@class='login-password-container login-components']//label[@class='origin-ux-textbox-label']");
    }

    public void doVerification(){
        WebDriverWait wait = new WebDriverWait(driver, 15);
        ExpectedCondition e = new ExpectedCondition<Boolean>() {
            @Override
            public Boolean apply(WebDriver d) {
                return (driver.findElement(By.xpath("//*[@id='panel-underage-login']//a[@id='continueBtn']")).getAttribute("class").matches(".*focus.*"));
            }
        };
        log.info(driver.getCurrentUrl());
        wait.until(e);
    }


}
